using System;
using System.Collections.Generic;
using NHibernate;
using Symbonix.NorSoNet.Framework.DAL.Entities;
using Symbonix.Library.Data.NHibernate;
using System.Collections;

namespace Symbonix.NorSoNet.Framework.DAL.Repositories
{
    public partial class EmailTemplateDataRepository : BaseRepository<EmailTemplateData, Int32>
    {
        public bool DeleteEmailTemplateByName(string name)
        {
            NHibernateHelper.BeginTransaction();
            try
            {
                ISession session = NHibernateHelper.CurrentSession;
                IQuery query = session.CreateSQLQuery(@"Delete from EmailTemplate where Name = :Name");
                query.SetAnsiString("Name", name);
                int result = query.ExecuteUpdate();

                NHibernateHelper.CommitTransaction();
                if (result > 0)
                    return true;
                else
                    return false;
            }
            catch (Exception exception)
            {
                NHibernateHelper.RollbackTransaction();
                return false;
            }
        }

        public EmailTemplateData GetByName(string name)
        {
            ISession session = NHibernateHelper.CurrentSession;
            IQuery query = session.CreateSQLQuery(@"select * from EmailTemplate where Name=:Name").AddEntity(typeof(EmailTemplateData));
            query.SetAnsiString("Name", name);
            return query.UniqueResult<EmailTemplateData>();
        }
        public bool IsNameExits(string name)
        {
            ISession session = NHibernateHelper.CurrentSession;
            IQuery query = session.CreateSQLQuery(@"select * from EmailTemplate where Name=:Name").AddEntity(typeof(EmailTemplateData));
            query.SetAnsiString("Name", name);
            IList list = query.List();
            if (list.Count > 0)
                return true;
            else
                return false;

        }

    }
}
